<template>
	
	<view>
	 		<!-- 自定义导航栏 -->
	 		<view class="navBarBox">
	 			<!-- 状态栏占位 -->
	 			<view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
	 			<!-- 真正的导航栏内容 -->
	 			<view class="navBar">
	 				<view class="goback">
	 					<view @click="goBack" class="goicon"style="background:url(../../static/goback.png);background-size:contain;background-repeat: no-repeat;">			
	 					</view>
	 				</view>
	 				<view class="title">班级管理</view>
	 				<view class="right">
	 					
	 				</view>
	 			</view>
	 		</view>
	 		<!-- 页面内容 -->
			<view class="centent">
				<!-- 06班级管理-编辑/新增-->
				
				<view class="centent1">
					
					<view>
						<text>班级信息</text>
					</view>
					
					<view class="centent1-1">
						<view>
							<text>班级名称</text>
							<!-- <input type="text" placeholder="一年级二班" :value="value | upper"> -->
							<text>{{value | upper}}</text>
						</view>
						<view >
							<text>入学年份</text>
							<text>{{value1 | yuzhou}}</text>
							<!-- <input type="text" placeholder="2019级入学" :value="value1 | yuzhou"> -->
						</view>
					</view>
				</view>
				
				<view class="centent2">
					<view><text>老师信息</text></view>
					
					<view class="centent2-1">
						<picker 
						@change="bindPickerChange" 
						:value="index" 
						:range="array"
						>{{array[index]}}</picker>
					</view>
					
				</view>
				
				<view class="centent3">
					<button @click="queding">确定</button>
				</view>
			</view>
	 	</view>
	
</template>

<script>
	export default {
		data() {
			// const currentDate = this.getDate({
			//             format: true
			//         })
			return {
				
				// 机构id或者学校id
				// Data:null,
				Data:{
					orgId:null
				},
				
				
				// 状态栏高度
				statusBarHeight: 0,
				// 导航栏高度
				navBarHeight: 82+11,
				
				// 年级
				value:'',
				// 入学年份
				value1:'',
				
				// 老师名字
				teacher:'',
				// 班级id,
				shuju:[],
				// t_id:'',
				
				// 选择老师
				title: 'picker',
				array: [],
				index: 0,
				
				// 班级id
				
				// 跟老师的名字一样不过渲染的是老师的id
				teacher1id:[],
				teacher2id:'',
			}
		},
		methods: {
			// 返回上一级
			goBack(){
				// 此处是写返回页面的方法、
							
				uni.navigateBack({
				    delta: 1//返回只上一级页面
				});
			},
			// 选择老师
			 bindPickerChange: function(e) {
			    console.log('picker发送选择改变，携带值为', e.target.value)
			    this.index = e.target.value
				this.teacher=this.array[e.target.value]
				// this.teacher1id[e.target.value]
				// 查询数组里面老师的id是否查询到了
				console.log(3333,this.teacher1id[e.target.value])
				// 传给后台的数据
				this.teacher2id=this.teacher1id[e.target.value]
				console.log(99999,this.teacher2id)
				console.log('老师',e)
				console.log(this.teacher)
			},
			queding(){
				console.log(this.shuju)
				this.$myRequest({
					url:'/admin/mclass/update',
					method:'POST',
					data:{
						id:this.shuju,
						teacherId:this.teacher2id
					},
					success: (res) => {
					    console.log('成功',res.data);
						uni.navigateTo({
							url:'./classmanaglist'
						})
					    // uni.showModal({
					    //     title: '提示',
					    //     content: '修改成功',
					    // 	showCancel	:false,
					    //     success: function (res) {
					    //         if (res.confirm) {
					    //             console.log('用户点击确定');
					    // 			// console.log('成功',v)
					    //         }
					    //     }
					    // });
					},
					fail:(err)=>{
						console.log('失败',err)
					}
				})
			},
			
			// 老师
			laoshi(){
				this.$myRequest({
					url:`/admin/teacher/finds/${this.Data.orgId}`,
					data:{
						
					},
					success:(res)=>{
						console.log(res.data.data)
						for(let i=0;i<res.data.data.length;i++){
							
							// 老师的名称
							this.array.push(res.data.data[i].teacherName)
							// 老师的id
							this.teacher1id.push(res.data.data[i].id)
							console.log(222,this.teacher1id)
							console.log(77777,res.data.data[i].teacherName)
							// console.log(123456,res.data.data[i].teacher)
							
						}
						
						// console.log(res.data.data)
					},
					fail:(err)=>{
						console.log(err)
					}
				})
			}

		},
		filters: {
		    upper: function(val) {
		        // return val.charAt(0).toUpperCase() + val.slice(1);
				
				let jiequ=val.slice(0,4)
				switch(jiequ){
					case '2017':
						jiequ='五年级';
						break;
					case '2018':
						jiequ='四年级';
						break;
					case '2019':
						jiequ='三年级';
						break;
					case '2020':
						jiequ='二年级';
						break;
					case '2021':
						jiequ='一年级';
						break;
					case '2016':
						jiequ='六年级';
						break;
				}
				return jiequ
		    },
			yuzhou:function(val){
				return val.slice(0,5)
				
			}
		},
		onLoad(option) {
			// console.log('老师',option)
			// console.log('老师名字',this.array[index])
			// console.log('上个页面的数据',option.v)
			
			// console.log(option.query)
			// const eventChannel = this.getOpenerEventChannel()
			// eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
			// eventChannel.emit('someEvent', {data: 'test'});
			// // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
			// eventChannel.on('acceptDataFromOpenerPage', function(data) {
			//   console.log(data,"接到的数据")
			// })
			
			
			const item = JSON.parse(decodeURIComponent(option.item));
			console.log('前一页数据',item);
			console.log('教师id',item.id)
			// this.t_id=item.id;
			this.shuju=item.id
			console.log(1111,this.shuju)
			// 编辑页面的前面
			this.value=item.className;
			this.value1=item.className
			
			
			
			// 老师一进来就渲染
			this.laoshi()
			
			
		},
		//第一次加载时调用
		created() {
			//获取手机状态栏高度
			this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
			
			
			// 获取学校机构的id
			// this.Data=uni.getStorageSync('schAdminConfirmData')
			
			if(uni.getStorageSync('schAdminConfirmData')){
				let Data1=uni.getStorageSync('schAdminConfirmData')
				this.Data.orgId=Data1.orgId
				console.log('学校id',this.Data.orgId)
			}else{
				let Data2=uni.getStorageSync('mechManagRegisterData')
				this.Data.orgId=Data2.id;
				console.log('机构id',this.Data.orgId)
			}
		},
	}
</script>	

<style lang="less">
	*{
		padding:0;
		margin:0
	}
	body{
		background: #e8e8ee;
	}
	
	 .navBarBox {}
	 
	 	.navBarBox .statusBar {}
	 
	 	.navBarBox .navBar {
	 		padding: 3rpx 50rpx;
	 		padding-bottom: 8rpx;
	 		display: flex;
	 		justify-content: space-between;
	 
	 		line-height: 93rpx;
	 		font-size: 40rpx;
	 	}
	 
	 	.goback {
	 		flex: 1;
	 		height: 100%;
	 	}
	 	.goicon{
	 		width: 30rpx;
	 		height: 30rpx;
	 		background-color: #00BEA9;
	 		margin-top: 30rpx;
	 	}
	 	.title {
	 		flex: 1;
	 		height: 100%;
	 		
	 	}
	 	.right{
	 		flex: 1;
	 	}
	
	
	.centent1{
		margin-top: 20rpx;
		background: 	#ffffff;
		padding: 40rpx 0 58rpx 0;
		&>view:nth-child(1){
			font-size: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;	
			width: 200rpx;
			height: 24rpx;
			background: #a2f8ee;
			margin: 30rpx 0 30rpx 30rpx;
			text{
				font-size: 38rpx;
			}
		}
	}
	.centent1>text{
		font-size: 38rpx;
		display: flex;
		/* padding-top: 40rpx; */
		padding-left: 30rpx;
	}
	.centent1-1{
		margin-top: 58rpx;
		margin-left: 90rpx;
		view:first-child{
			display: flex;
			flex-direction: row;
			input{
				margin-left: 90rpx;
			}
		}
		view:last-child{
			display: flex;
			flex-direction: row;
			input{
				margin-left: 90rpx;
			}
		}
	}
	.centent1-1 view:nth-child(2){
		margin-top:74rpx;
	}
	.centent1-1 view text:first-child{
		color:rgba(18,18,18,0.5) ;
		font-size: 32rpx;
	}
	.centent1-1 view text:nth-child(2){
		margin-left: 84rpx;
		color: #121212;
		font-size: 32rpx;
	}
	.centent2{
		margin-top: 20rpx;
		background: #FFFFFF;
		padding-top:40rpx;
		padding-bottom:58rpx;
		border-bottom: 1px solid #cfcfd4;
		display: flex;
		flex-direction: column;
		// padding-left:30rpx;
		&>view:nth-child(1){
			font-size: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;	
			width: 200rpx;
			height: 24rpx;
			background: #a2f8ee;
			margin: 30rpx 0 30rpx 30rpx;
			text{
				font-size: 38rpx;
			}
		}
	}
	.centent2>text{
		font-size: 38rpx;
	}
	.centent2>view:nth-child(2){
		margin-top: 58rpx;
		font-size: 32rpx;
		margin-left: 30rpx;
	}
	.centent3{
		margin-top: 60rpx;
		display: flex;
		justify-content: center;
		button{
			width: 230rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: #2db3fe;
			color: #FFFFFF;
			box-shadow: 2rpx 3rpx 1rpx #2db3fe;
		}
	}
</style>
